package edu.nf.vac.admin.controller;

import edu.nf.vac.admin.vo.ResultVO;
import edu.nf.vac.vaccination.dto.AreaDTO;
import edu.nf.vac.vaccination.dto.VaccinationDTO;
import edu.nf.vac.vaccination.dto.VaccinationPageDTO;
import edu.nf.vac.vaccination.inf.VaccinationService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author : QYM
 * @create 2022/4/6
 */
@RestController
public class VaccinationController extends BaseController{
    @DubboReference(interfaceClass = VaccinationService.class,version = "1.0.0")
    private VaccinationService vaccinationService;
    /**
     * 查询所有区域
     * @return
     */
    @GetMapping("/area/list")
    public ResultVO<List<AreaDTO>> listArea(){
        List<AreaDTO> list = vaccinationService.listArea();
        return success(list);
    }

    /**
     * 根据区域查询接种点
     * @param areaId
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/vaccination/list")
    public ResultVO<List<VaccinationDTO>> listVaccination(Integer areaId, Integer page, Integer limit){
        VaccinationPageDTO pageDTO = vaccinationService.listVaccination(areaId, page, limit);
        return pageResult(pageDTO.getTotal(),pageDTO.getList());
    }

    /**
     * 根据id查询接种点
     * @param id
     * @return
     */
    @GetMapping("/vaccination/{id}")
    public ResultVO<VaccinationDTO> getVaccinationById(@PathVariable("id") Integer id){
        VaccinationDTO vaccinationDTO = vaccinationService.getVaccinationById(id);
        return success(vaccinationDTO);
    }

    /**
     * 添加接种点
     * @param dto
     */
    @PostMapping("/vaccination/add")
    public ResultVO saveVaccination(VaccinationDTO dto){
        vaccinationService.saveVaccination(dto);
        return success();
    }

    /**
     * 修改接种点
     * @param dto
     */
    @PostMapping("/vaccination/update")
    public ResultVO updateVaccination(VaccinationDTO dto){
        vaccinationService.updateVaccination(dto);
        return success();
    }
}
